package com.itheima.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.order.client.UserClient;
import com.itheima.order.domain.po.Order;
import com.itheima.order.domain.po.User;
import com.itheima.order.domain.vo.OrderVo;
import com.itheima.order.mapper.OrderMapper;
import com.itheima.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserClient userClient;

    @Override
    public OrderVo getOrder(Long id) {

        Order order = orderMapper.selectById(id);

        OrderVo orderVo = BeanUtil.copyProperties(order, OrderVo.class);

        Long userId = order.getUserId();

        User user = userClient.getUser(userId);
        orderVo.setUser(user);
        return orderVo;
    }
}
